package greedy.区间选择;

import java.util.Arrays;
import java.util.Comparator;

public class leetcode435无重叠区间 {
    public int eraseOverlapIntervals(int[][] intervals) {
        int group = intervals.length;
        Arrays.sort(intervals, Comparator.comparingInt(o -> o[1]));
        int right = intervals[0][1];
        int count = 1;
        for (int i = 1; i < group; i++) {
            if (intervals[i][0] >= right) {
                count++;
                right = intervals[i][1];
            }
        }
        return group - count;
    }
}
